package com.lh.tams.controller.system;

import java.util.Date;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lh.tams.controller.qo.MinLawQo;
import com.lh.tams.domain.TamsMaxLaw;
import com.lh.tams.domain.TamsMinLaw;
import com.lh.tams.domain.TamsPerson;
import com.lh.tams.service.system.LawMinService;
import com.lh.tams.util.Constants;
import com.lh.tams.util.DataGridModel;
import com.lh.tams.util.ID;
import com.lh.tams.util.Page;
import com.lh.tams.util.Status;
import com.lh.tams.util.diy.Json;

/**
 * 法律法规小类管理controller
 * @author liulin
 * @version 2012-06-20
 */
@RequestMapping("/lawmin")
@Controller
public class LawMinController {
	private LawMinService lawMinService;

	public LawMinService getLawMinService() {
		return lawMinService;
	}

	public void setLawMinService(LawMinService lawMinService) {
		this.lawMinService = lawMinService;
	}

	@RequestMapping("/query.adm")
	@ResponseBody
	public Page query(DataGridModel dgm,MinLawQo minLawQo){
		//tamsMinLaw.setTamsMaxLaw(new TamsMaxLaw(maxId));
		return lawMinService.query(dgm, minLawQo);
	}
	
	@RequestMapping("/add.adm")
	@ResponseBody
	public Json add(TamsMinLaw tamsMinLaw,long maxId,HttpSession session){
		TamsPerson person= (TamsPerson) session.getAttribute(Constants.ADMIN_SESSION_KEY);
		tamsMinLaw.setIdBgt(ID.next());
		tamsMinLaw.setStatus(Status.STATUS_NORMAL);
		tamsMinLaw.setTamsMaxLaw(new TamsMaxLaw(maxId));
		tamsMinLaw.setTamsPerson(person);
		tamsMinLaw.setCreateDate(new Date());
		lawMinService.add(tamsMinLaw);
		Json json = new Json();
		return json;
	}
	
	@RequestMapping("/update.adm")
	@ResponseBody
	public Json update(TamsMinLaw tamsMinLaw,long maxId,HttpSession session){
		TamsPerson person= (TamsPerson) session.getAttribute(Constants.ADMIN_SESSION_KEY);
		tamsMinLaw.setStatus(Status.STATUS_NORMAL);
		tamsMinLaw.setTamsMaxLaw(new TamsMaxLaw(maxId));
		tamsMinLaw.setTamsPerson(person);
		lawMinService.update(tamsMinLaw);
		Json json = new Json();
		return json;
	}
	
	@RequestMapping("/del.adm")
	@ResponseBody
	public Json delete(long[] id){
		lawMinService.delete(id);
		return new Json();
	}
}
